#ifndef STRINGHELPER_H
#define STRINGHELPER_H

#include <algorithm>
#include <cctype>
#include "stdafx.h"

namespace CExpression
{
	class StringHelper
	{
	public:
		static bool IsOperatorChar(ExpressionChar character)
		{
			return character==TEXT('+')||character==TEXT('-')||character==TEXT('*')||character==TEXT('/')||
				character==TEXT('>')||character==TEXT('<')||character==TEXT('=')||
				character==TEXT('&')||character==TEXT('|')||character==TEXT('!')||
				character==TEXT('~')||character==TEXT(',');
		}

		static bool IsUnitaryOperatorChar(ExpressionChar character)
		{
			return character == TEXT('-') || character == TEXT('+') ||
                character == TEXT('~') || character == TEXT('!');
		}

		static bool IsNoneUnitaryOperatorChar(ExpressionChar character)
		{
			return character == TEXT('*') || character == TEXT('/') ||
                character == TEXT('>') || character == TEXT('<') || character == TEXT('=')||
				character == TEXT('&') || character == TEXT('|') || character == TEXT(',');
		}

		static bool IsSpecialChar(ExpressionChar character)
		{
			return character == TEXT('(')||character == TEXT(')')||character == TEXT(',');
		}

		static bool IsSpaceChar(ExpressionChar character)
		{
			return character==TEXT('\n')||character==TEXT(' ')||character==TEXT('\t')||character==TEXT('\r');
		}

		static void ToLower(ExpressionString &str)
		{
			ToLower(str,str.begin());
		}

		static void ToLower(ExpressionString &str,ExpressionString::iterator dest)
		{
			transform(str.begin(),str.end(),dest,tolower);
		}

		static void ToUpper(ExpressionString &str)
		{
			ToUpper(str,str.begin());
		}

		static void ToUpper(ExpressionString &str,ExpressionString::iterator dest)
		{
			transform(str.begin(),str.end(),dest,toupper);
		}

		static bool StartWith(const ExpressionString &str1,const ExpressionString &str2)
		{
			if(str1.size()<str2.size())
			{
				return false;
			}
			else
			{
				return equal(str2.begin(),str2.end(),str1.begin());
			}
		}

		static bool EndWith(const ExpressionString &str1,const ExpressionString &str2)
		{
			if(str1.size()<str2.size())
			{
				return false;
			}
			else
			{
				return equal(str2.rbegin(),str2.rend(),str1.rbegin());
			}
		}
	};
}

#endif